package com.ruoyi.bcsettings.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.bcsettings.domain.ErpEnterprise;
import com.ruoyi.bcsettings.service.IErpEnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 企业管理Controller
 * 
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/bcsettings/enterprise")
public class ErpEnterpriseController extends BaseController
{
    @Autowired
    private IErpEnterpriseService erpEnterpriseService;

    /**
     * 查询企业管理列表
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:enterprise:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpEnterprise erpEnterprise)
    {
        startPage();
        List<ErpEnterprise> list = erpEnterpriseService.selectErpEnterpriseList(erpEnterprise);
        return getDataTable(list);
    }

    /**
     * 导出企业管理列表
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:enterprise:export')")
    @Log(title = "企业管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpEnterprise erpEnterprise)
    {
        List<ErpEnterprise> list = erpEnterpriseService.selectErpEnterpriseList(erpEnterprise);
        ExcelUtil<ErpEnterprise> util = new ExcelUtil<ErpEnterprise>(ErpEnterprise.class);
        util.exportExcel(response, list, "企业管理数据");
    }

    /**
     * 获取企业管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:enterprise:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(erpEnterpriseService.selectErpEnterpriseById(id));
    }

    /**
     * 新增企业管理
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:enterprise:add')")
    @Log(title = "企业管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpEnterprise erpEnterprise)
    {
        return toAjax(erpEnterpriseService.insertErpEnterprise(erpEnterprise));
    }

    /**
     * 修改企业管理
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:enterprise:edit')")
    @Log(title = "企业管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpEnterprise erpEnterprise)
    {
        return toAjax(erpEnterpriseService.updateErpEnterprise(erpEnterprise));
    }

    /**
     * 删除企业管理
     */
    @PreAuthorize("@ss.hasPermi('bcsettings:enterprise:remove')")
    @Log(title = "企业管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(erpEnterpriseService.deleteErpEnterpriseByIds(ids));
    }
}
